Add structural reranking to code search - #12
Merged
Conversation
The CLI `ccg search` and the MCP `search` tool returned FTS candidates in raw BM25 order. Introduce internal/searchrank, a dependency-free reranker that fuses the FTS rank with two structural signals via Reciprocal Rank Fusion: - name fuzzy similarity (rune Levenshtein over the whole name and camelCase sub-tokens, plus the run-together query for typos), and - path proximity (query tokens matching file-path segments). Name is weighted above path so an exact-name match outranks a mere same-file hit. Both surfaces over-fetch a wider candidate pool (searchrank.FetchLimit) so reranking can promote good matches FTS ranked below the caller's limit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
배경
ccg search(CLI)와 MCPsearch도구가 FTS 후보를 raw BM25 순서 그대로 반환했다.동의어·오타·내부 단어 쿼리에서 관련도 높은 심볼이 상위로 오지 못했다.
DeusData/codebase-memory-mcp의 "combined scoring" 아이디어를 임베딩/외부 서비스
없이 차용한 Tier-0 개선이다.
변경
internal/searchrank— 의존성 없는 리랭커. FTS rank와 두 구조 신호를Reciprocal Rank Fusion으로 융합:
join된 쿼리).
searchrank.FetchLimit) → FTS가 limit아래로 매긴 좋은 매치도 리랭크가 끌어올릴 수 있음.
internal/cli/search.go)와 MCP(internal/mcp/handler_query.go) 양쪽 배선.실측 (
ccg build ./internal, 1523 노드)rerankfetch limit검증
CGO_ENABLED=1 go test -tags "fts5" ./... -count=1— 전체 greengo vet클린알려진 한계 / 후속
FTS
unicode61+ prefix-only 토크나이저가 camelCase를 안 쪼개, 순수 오타·내부단어 쿼리는 FTS가 0건 반환 → 리랭크가 recall을 못 늘림(precision만 개선). 다음
레버는 camelCase-aware FTS 토크나이징 (별도 태스크로 계획됨).
🤖 Generated with Claude Code